//package com.geekerp.authorization_server.sms;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.springframework.security.authentication.AuthenticationServiceException;
//import org.springframework.security.core.Authentication;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
//
//public class SmsCodeAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
//    private static final String SPRING_SECURITY_FORM_PHONE_KEY = "phone";
//    private static final String SPRING_SECURITY_FORM_SMS_CODE_KEY = "smsCode";
//
//    public SmsCodeAuthenticationFilter() {
//        super("/login/sms");
//    }
//
//    @Override
//    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
//        if (!request.getMethod().equals("POST")) {
//            throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
//        }
//
//        String phone = obtainPhone(request);
//        String smsCode = obtainSmsCode(request);
//
//        if (phone == null) {
//            phone = "";
//        }
//
//        if (smsCode == null) {
//            smsCode = "";
//        }
//
//        phone = phone.trim();
//
//        SmsCodeAuthenticationToken authRequest = new SmsCodeAuthenticationToken(phone, smsCode);
//        setDetails(request, authRequest);
//
//        return this.getAuthenticationManager().authenticate(authRequest);
//    }
//
//    protected String obtainPhone(HttpServletRequest request) {
//        return request.getParameter(SPRING_SECURITY_FORM_PHONE_KEY);
//    }
//
//    protected String obtainSmsCode(HttpServletRequest request) {
//        return request.getParameter(SPRING_SECURITY_FORM_SMS_CODE_KEY);
//    }
//
//    protected void setDetails(HttpServletRequest request, SmsCodeAuthenticationToken authRequest) {
//        authRequest.setDetails(this.authenticationDetailsSource.buildDetails(request));
//    }
//}